<!--
 * @Descripttion: (房型表/lay_room)
 * @Author: (admin)
 * @Date: (2024-09-29)
-->
<template>
  <div>
    <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
      <el-form-item label="民宿" prop="houseId">
        <el-select clearable multiple v-model="queryParams.houseId" placeholder="请选择房屋id">
          <el-option v-for="item in options.sql_house " :key="item.dictValue" :label="item.dictLabel"
            :value="item.dictValue">
            <span class="fl">{{ item.dictLabel }}</span>
            <span class="fr" style="color: var(--el-text-color-secondary);">{{ item.dictValue }}</span>
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
        <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
      </el-form-item>
    </el-form>
    <!-- 工具区域 -->
    <el-row :gutter="15" class="mb10">
      <el-col :span="1.5">
        <el-button type="primary" v-hasPermi="['layroom:add']" plain icon="plus" @click="handleAdd">
          {{ $t('btn.add') }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" :disabled="single" v-hasPermi="['layroom:edit']" plain icon="edit"
          @click="handleUpdate">
          {{ $t('btn.edit') }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" v-hasPermi="['layroom:delete']" plain icon="delete"
          @click="handleDelete">
          {{ $t('btn.delete') }}
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="download" @click="handleExport" v-hasPermi="['layroom:export']">
          {{ $t('btn.export') }}
        </el-button>
      </el-col> -->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table :data="dataList" v-loading="loading" ref="table" border header-cell-class-name="el-table-header-cell"
      highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <!-- <el-table-column align="center" width="90">
        <template #default="scope">
          <el-button text @click="rowClick(scope.row)">{{ $t('btn.details') }}</el-button>
        </template>
</el-table-column> -->
      <el-table-column prop="name" label="名称" align="center" width="300" :show-overflow-tooltip="true"
        v-if="columns.showColumn('name')" />
      <!-- <el-table-column prop="title" label="标题" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('title')"/> -->

      <!-- <el-table-column prop="isBreakfast" label="早餐" align="center" v-if="columns.showColumn('isBreakfast')">
        <template #default="scope">
          {{ scope.row.isBreakfast == "1" ? "有早餐" : "无早餐" }}
        </template>
      </el-table-column>
      <el-table-column prop="isWhole" label="整租" align="center" v-if="columns.showColumn('isWhole')">
        <template #default="scope">
          {{ scope.row.isWhole == "1" ? "整租" : "" }}
        </template>
      </el-table-column> -->
      <el-table-column prop="roomSize" label="房间面积" width="90" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('roomSize')" />
      <el-table-column prop="roomNum" label="房间数" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('roomNum')" />
      <el-table-column prop="bedNum" label="床位" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('bedNum')" />
      <el-table-column prop="toiletNum" label="卫生间" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('toiletNum')" />
      <el-table-column prop="personNum" label="入住数" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('personNum')" />
      <el-table-column prop="stockNum" label="库存" align="center" v-if="columns.showColumn('stockNum')" />
      <!-- <el-table-column prop="id" label="Id" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('id')"/> -->\
      <el-table-column prop="linePrice" label="划线价" width="85" align="center" v-if="columns.showColumn('linePrice')" />
      <el-table-column prop="dailyPrice" label="日常价格" width="90" align="center"
        v-if="columns.showColumn('dailyPrice')" />
      <el-table-column prop="weekPrice" label="周末价格" width="90" align="center" v-if="columns.showColumn('weekPrice')" />
      <el-table-column prop="holidayPrice" label="节假价格" width="85" align="center"
        v-if="columns.showColumn('holidayPrice')" />

      <!-- <el-table-column prop="imageUrl" label="图片地址" align="center" v-if="columns.showColumn('imageUrl')">
        <template #default="scope">
          <ImagePreview :src="scope.row.imageUrl"></ImagePreview>
        </template>
      </el-table-column> -->
      <el-table-column prop="tags" label="标签" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('tags')" />
      <el-table-column prop="content" label="介绍" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('content')" />

      <el-table-column prop="showDays" label="预定展示天数" align="center" v-if="columns.showColumn('showDays')" />
      <el-table-column prop="houseId" label="民宿" align="center" v-if="columns.showColumn('houseId')">
        <template #default="scope">
          <dict-tag :options="options.sql_house" :value="scope.row.houseId" split="," />
        </template>
      </el-table-column>
      <el-table-column prop="createBy" label="创建人" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('createBy')" />
      <el-table-column prop="createTime" label="创建时间" :show-overflow-tooltip="true"
        v-if="columns.showColumn('createTime')" />



      <el-table-column prop="status" label="状态" width="55" align="center" v-if="columns.showColumn('status')">
        <template #default="scope">
          <dict-tag :options="options.status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="160">
        <template #default="scope">
          <el-button type="success" size="small" icon="edit" title="编辑" v-hasPermi="['layroom:edit']"
            @click="handleUpdate(scope.row)"></el-button>
          <el-button type="danger" size="small" icon="delete" title="删除" v-hasPermi="['layroom:delete']"
            @click="handleDelete(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />

    <el-drawer v-model="drawer" size="50%" direction="rtl">
      <el-table :data="layRoomSpecList" header-row-class-name="text-navy">
        <el-table-column label="序号" type="index" width="80" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="roomId" label="房型id" />
        <el-table-column prop="specName" label="规格名称" />
        <el-table-column prop="specTitle" label="规格标题" />
        <el-table-column prop="linePrice" label="划线价" />
        <el-table-column prop="dailyPrice" label="日常价格" />
        <el-table-column prop="weekPrice" label="周末价格" />
        <el-table-column prop="holidayPrice" label="节假日" />
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <dict-tag :options="options.statusOptions" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column prop="statusName" label="状态名称">
          <template #default="scope">
            <dict-tag :options="options.statusNameOptions" :value="scope.row.statusName" />
          </template>
        </el-table-column>
      </el-table>
    </el-drawer>
    <!-- ====================================== -->
    <el-dialog :title="title" :lock-scroll="false" v-model="open" :fullscreen="fullScreen" :with="2000"
      :close-on-click-modal="false">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
        <el-tabs type="border-card">
          <el-tab-pane label="基础信息">
            <el-row :gutter="20">
              <el-col :lg="18">
                <el-col :lg="24">
                  <el-form-item label="民宿" prop="houseId">
                    <el-select v-model="form.houseId" placeholder="请选择民宿" style="width: 100%;">
                      <el-option v-for="item in houseList" :key="item.id" :label="item.name"
                        :value="item.id"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :lg="24">
                  <el-form-item label="名称" prop="name">
                    <el-input v-model="form.name" placeholder="请输入名称" />
                  </el-form-item>
                </el-col>
                <el-col :lg="24">
                  <el-form-item label="标题" prop="title">
                    <el-input v-model="form.title" placeholder="请输入标题" />
                  </el-form-item>
                </el-col>
                <el-col :lg="24">
                  <el-form-item label="介绍" prop="content">
                    <el-input type="textarea" :row="3" maxlength="150" v-model="form.content" placeholder="请输入介绍" />
                  </el-form-item>
                </el-col>

              </el-col>

              <el-col :lg="6"> <el-form-item label="状态" prop="status">
                  <el-select v-model="form.status">
                    <el-option v-for="item in options.status" :key="item.dictValue" :value="item.dictValue"
                      :label="item.dictLabel" />
                  </el-select>
                </el-form-item>
                <!-- <el-form-item label="" prop="imageUrl"> -->
                <UploadImage v-model="form.mainImageUrl" :data="{ uploadType: 1 }" />
                <!-- </el-form-item>  -->
              </el-col>
              <el-col :lg="24">
                <el-form-item label="标签" prop="tags">
                  <el-input type="textarea" v-model="form.tags" placeholder="请输入标签" />
                </el-form-item>
              </el-col>
              <el-col :lg="6">
                <el-form-item label="库存数量" prop="stockNum">
                  <el-input type="number" v-model="form.stockNum" :min="1" placeholder="库存数量">
                    <template #suffix>套</template>
                  </el-input>
                </el-form-item>

              </el-col>

              <el-col :lg="6">
                <el-form-item label="房间面积" prop="roomSize">
                  <el-input type="number" v-model="form.roomSize" :min="1" placeholder="房间面积">
                    <template #suffix>m²</template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :lg="6">
                <el-form-item label="卫生间" prop="toiletNum">
                  <el-input type="number" v-model="form.toiletNum" :min="1" placeholder="卫生间">
                    <template #suffix>卫</template>
                  </el-input>
                </el-form-item>
              </el-col>

              <el-col :lg="6">
                <el-form-item label="床位数" prop="bedNum">
                  <el-input type="number" v-model="form.bedNum" :min="1" placeholder="床位数">
                    <template #suffix>位</template>
                  </el-input>
                </el-form-item>
              </el-col>

              <el-col :lg="6">
                <el-form-item label="房间数" prop="roomNum">
                  <el-input type="number" v-model="form.roomNum" :min="1" placeholder="房间数">
                    <template #suffix>室</template>
                  </el-input>
                </el-form-item>
              </el-col>

              <el-col :lg="6">
                <el-form-item label="入住人数" prop="personNum">
                  <el-input v-model="form.personNum" placeholder="入住人数">
                    <template #suffix>人</template>
                  </el-input>
                </el-form-item>
              </el-col>

              <!-- <el-col :lg="6">
                <el-form-item label="展示天数" prop="showDays">
                  <el-input-number v-model.number="form.showDays" :min="1" placeholder="展示天数" />
                </el-form-item>
              </el-col> -->
              <!-- <el-col :lg="3">
                <el-checkbox :true-label="'1'" :false-label="'0'" :checked="form.isBreakfast == '1' ? true : false"
                  v-model="form.isBreakfast">是否早餐</el-checkbox>
              </el-col>
              <el-col :lg="3">

                <el-checkbox :true-label="'1'" :false-label="'0'" :checked="form.isWhole == '1' ? true : false"
                  v-model="form.isWhole">是否整租</el-checkbox>
              </el-col> -->

              <!-- <el-col :lg="24">
            <el-form-item label="图标" prop="icon">
              <UploadImage v-model="form.icon" :data="{ uploadType: 1 }" />
            </el-form-item>
          </el-col> -->
              <!-- <el-col :lg="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>  -->
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="房型价格表">
            <el-divider content-position="center">房型规格信息</el-divider>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" icon="Plus" @click="handleAddLayRoomSpec">添加</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" icon="Delete" @click="handleDeleteLayRoomSpec">删除</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="info" icon="FullScreen" @click="fullScreen = !fullScreen">{{ fullScreen ? '退出全屏' : '全屏'
                  }}</el-button>
              </el-col>
            </el-row>
            <el-table :data="layRoomSpecList" :row-class-name="rowLayRoomSpecIndex"
              @selection-change="handleLayRoomSpecSelectionChange" ref="LayRoomSpecRef">
              <el-table-column type="selection" width="40" align="center" />
              <el-table-column label="序号" align="center" prop="index" width="55" />
              <el-table-column label="套餐名称" align="center" prop="specName" width="230">
                <template #default="scope">
                  <el-input v-model="scope.row.specName" placeholder="请输入套餐名称" />
                </template>
              </el-table-column>
              <!-- <el-table-column label="标题" align="center" prop="specTitle">
              <template #default="scope">
                <el-input v-model="scope.row.specTitle" placeholder="规格标题" />
              </template>
            </el-table-column> -->
              <el-table-column label="划线价" align="center" prop="linePrice" width="110">
                <template #default="scope">
                  <el-input type="number" v-model="scope.row.linePrice" :precision="2" :min="1" placeholder="划线价">
                    <template #suffix>元</template>
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="日常价格" align="center" prop="dailyPrice" width="110">
                <template #default="scope">
                  <el-input type="number" v-model="scope.row.dailyPrice" :precision="2" :min="1" placeholder="日常价格">
                    <template #suffix>元</template>
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="周末价格" align="center" :precision="2" prop="weekPrice" width="110">
                <template #default="scope">
                  <el-input type="number" v-model="scope.row.weekPrice" :precision="2" :min="1" placeholder="周末价格">
                    <template #suffix>元</template>
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="节假价格" align="center" prop="holidayPrice" width="110">
                <template #default="scope">
                  <el-input type="number" v-model="scope.row.holidayPrice" :precision="2" :min="1" placeholder="节假价格">
                    <template #suffix>元</template>
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="状态" align="center" prop="status">
                <template #default="scope">
                  <el-select v-model="scope.row.status" placeholder="请选择状态" style="width:90%">
                    <el-option v-for="item in options.status" :key="item.dictValue" :label="item.dictLabel"
                      :value="item.dictValue"></el-option>
                  </el-select>
                </template>
              </el-table-column>

            </el-table>
          </el-tab-pane>
          <el-tab-pane label="属性信息">
            <el-tree class="tree-border" :data="PriceOptions" default-expand-all show-checkbox ref="PriceRef"
              node-key="id" empty-text="加载中，请稍后" highlight-current :props="{ children: 'children', label: 'name' }">
              <template #default="{ node, data }">
                <div class="custom-tree-node">
                  <span class="fl" :title="data.label">{{ node.label }}</span>
                </div>
              </template>
            </el-tree>
            <el-tree class="tree-border" :data="AttrOptions" default-expand-all show-checkbox ref="AttrRef"
              node-key="id" empty-text="加载中，请稍后" highlight-current :props="{ children: 'children', label: 'name' }">
              <template #default="{ node, data }">
                <div class="custom-tree-node">
                  <span class="fl" :title="data.label">{{ node.label }}</span>
                </div>
              </template>
            </el-tree>
          </el-tab-pane>
          <el-tab-pane label="图文相册">
            <el-col :lg="24">
              <!-- <el-form-item label="详情图" prop="imageUrl"> -->
              <UploadImage v-model="form.imageUrl" :limit="5" :data="{ uploadType: 1 }" />
              <!-- </el-form-item> -->
            </el-col>
          </el-tab-pane>



        </el-tabs>
      </el-form>
      <template #footer v-if="opertype != 3">
        <el-button text @click="cancel">{{ $t('btn.cancel') }}</el-button>
        <el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="layroom">
import {
  listLayRoom,
  addLayRoom, delLayRoom,
  updateLayRoom, getLayRoom, listLayCompanyHouse
}
  from '@/api/business/layroom.js'
import { min } from 'xe-utils';

import { treelistLayPriceRange } from '@/api/business/laypricerange.js';

import { treelistLayAttr } from '@/api/business/layattr.js';
const { proxy } = getCurrentInstance()
const ids = ref([])
const loading = ref(false)
const showSearch = ref(true)
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  sort: 'CreateTime',
  sortType: 'asc',
  houseId: undefined,
})
const columns = ref([
  { visible: true, align: 'center', type: '', prop: 'holidayPrice', label: '节假价格' },
  { visible: true, align: 'center', type: '', prop: 'createBy', label: '创建人', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'createTime', label: '创建时间', showOverflowTooltip: true },
  { visible: true, align: 'center', type: 'dict', prop: 'status', label: '状态', showOverflowTooltip: true, dictType: 'status' },
  { visible: true, align: 'center', type: 'dict', prop: 'isBreakfast', label: '是否早餐', showOverflowTooltip: true },
  { visible: true, align: 'center', type: 'dict', prop: 'isWhole', label: '整租', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'roomSize', label: '房间面积', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'toiletNum', label: '卫生间', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'bedNum', label: '床位', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'roomNum', label: '房间数', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'personNum', label: '入住人数', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'stockNum', label: '库存数量' },
  // { visible: false, align: 'center', type: '', prop: 'id', label: 'Id'  ,showOverflowTooltip: true  },
  { visible: true, align: 'center', type: '', prop: 'weekPrice', label: '周末价格' },
  { visible: true, align: 'center', type: '', prop: 'dailyPrice', label: '日常价格' },
  { visible: true, align: 'center', type: '', prop: 'linePrice', label: '划线价' },
  { visible: true, align: 'center', type: 'img', prop: 'imageUrl', label: '图片地址', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'tags', label: '标签', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'content', label: '介绍', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'title', label: '标题', showOverflowTooltip: true },
  { visible: true, align: 'center', type: '', prop: 'name', label: '名称', showOverflowTooltip: true },
  { visible: false, align: 'center', type: '', prop: 'showDays', label: '展示天数' },
  { visible: false, align: 'center', type: 'dict', prop: 'houseId', label: '民宿', showOverflowTooltip: true, dictType: 'sql_house' },
  //{ visible: false, prop: 'actions', label: '操作', type: 'slot', width: '160' }
])
const total = ref(0)
const dataList = ref([])
const houseList = ref([])
const queryRef = ref()
const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])

var dictParams = [
  "status",
  "sql_house",
]

proxy.getDicts(dictParams).then((response) => {
  response.data.forEach((element) => {
    state.options[element.dictType] = element.list
  })
})

listLayCompanyHouse().then(res => {
  const { code, data } = res
  if (code == 200) {
    houseList.value = data

  }
  console.log("houseList", houseList.value);
})
function getList() {
  loading.value = true
  listLayRoom(queryParams).then(res => {
    const { code, data } = res
    if (code == 200) {
      dataList.value = data.result
      total.value = data.totalNum
      loading.value = false
    }
  })
}

// 查询
function handleQuery() {
  queryParams.pageNum = 1
  getList()
}

// 重置查询操作
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}
// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1
  multiple.value = !selection.length;
}
// 自定义排序
function sortChange(column) {
  var sort = undefined
  var sortType = undefined

  if (column.prop != null && column.order != null) {
    sort = column.prop
    sortType = column.order

  }
  queryParams.sort = sort
  queryParams.sortType = sortType
  handleQuery()
}

/*************** form操作 ***************/
const formRef = ref()
const title = ref('')
// 操作类型 1、add 2、edit 3、view
const opertype = ref(0)
const open = ref(false)
const PriceRef = ref()
const PriceOptions = ref([])

const AttrRef = ref()
const AttrOptions = ref([])

const state = reactive({
  single: true,
  multiple: true,
  form: {},
  rules: {
    roomSize: [{ required: true, message: "房间面积不能为空", trigger: "blur" }],
    toiletNum: [{ required: true, message: "卫生间不能为空", trigger: "blur" }],
    bedNum: [{ required: true, message: "床位数不能为空", trigger: "blur" }],
    roomNum: [{ required: true, message: "房间数不能为空", trigger: "blur" }],
    personNum: [{ required: true, message: "入住人数不能为空", trigger: "blur" }],
    stockNum: [{ required: true, message: "库存数量不能为空", trigger: "blur" }],
    // id: [{ required: true, message: "Id不能为空", trigger: "blur"     }],
    // weekPrice: [{ required: true, message: "周末价格不能为空", trigger: "blur"     }],
    // dailyPrice: [{ required: true, message: "日常价格不能为空", trigger: "blur"     }],
    // linePrice: [{ required: true, message: "划线价不能为空", trigger: "blur"     }],
    // title: [{ required: true, message: "标题不能为空", trigger: "blur"     }],
    name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
  },
  options: {
    // 状态名称 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
    statusNameOptions: [],
    // 状态 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
    status: [],
    // 房屋id 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
    sql_house: [],
    isBreakfast: [{ "dictLabel": "有无早餐", "dictvalue": "1" }],
    isWhole: [{ "dictLabel": "是否整租", "dictvalue": "1" }]
  }
})

const { form, rules, options, single, multiple } = toRefs(state)

// 关闭dialog
function cancel() {
  open.value = false
  reset()
}

// 重置表单
function reset() {
  if (proxy.$refs.priceRef != undefined) {
    proxy.$refs.priceRef.setCheckedKeys([])
  };
  if (proxy.$refs.AttrRef != undefined) {
    proxy.$refs.AttrRef.setCheckedKeys([])
  };
  (form.value = {
    holidayPrice: null,
    updateBy: null,
    updateTime: null,
    createBy: null,
    createTime: null,
    statusName: null,
    status: null,
    isBreakfast: null,
    isWhole: null,
    roomSize: null,
    toiletNum: null,
    bedNum: null,
    roomNum: null,
    personNum: null,
    stockNum: null,
    mainImageUrl: null,
    id: null,
    weekPrice: null,
    dailyPrice: null,
    linePrice: null,
    imageUrl: null,
    icon: null,
    tags: null,
    remark: null,
    info: null,
    content: null,
    title: null,
    name: null,
    showDays: null,
    houseId: null,
    attrIds: [],
    priceIds: [],
  });
  layRoomSpecList.value = []
  proxy.resetForm("formRef")
}
//民宿获取位置信息
const PriceParams = reactive({
  status: '1'

})
treelistLayPriceRange(PriceParams).then(res => {
  const { code, data } = res
  if (code == 200) {
    PriceOptions.value = data
    console.log(data)
  }
})
const AttrParams = reactive({
  status: '1'
})
treelistLayAttr(AttrParams).then(res => {
  const { code, data } = res
  if (code == 200) {
    AttrOptions.value = data
    console.log(data)
  }
})
// 添加按钮操作
function handleAdd() {
  reset();
  open.value = true
  title.value = '添加房型表'
  opertype.value = 1
  form.value.status = '1'
}
// 修改按钮操作
function handleUpdate(row) {
  reset()
  const id = row.id || ids.value
  getLayRoom(id).then((res) => {
    const { code, data } = res
    if (code == 200) {
      open.value = true
      title.value = '修改房型表'
      opertype.value = 2

      form.value = {
        ...data,
        // isBreakfast: data.isBreakfast ,
        // isWhole: data.isWhole ,
        // houseId: data.houseId ,
      }
      layRoomSpecList.value = res.data.layRoomSpecNav
      if (data.priceIds != null) {
        data.priceIds.forEach((v) => {
          nextTick(() => {
            proxy.$refs.PriceRef.setChecked(v, true, false)
          })
        })
      }
      if (data.attrIds != null) {
        data.attrIds.forEach((v) => {
          nextTick(() => {
            proxy.$refs.AttrRef.setChecked(v, true, false)
          })
        })
      }
    }
  })
}
// 所有菜单节点数据
function getPriceAllCheckedKeys() {
  // 目前被选中的菜单节点
  const checkedKeys = proxy.$refs.PriceRef.getCheckedKeys()
  // 半选中的菜单节点
  // const halfCheckedKeys = proxy.$refs.PriceRef.getHalfCheckedKeys()
  // checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys)
  return checkedKeys
}
// 所有菜单节点数据
function getAttrAllCheckedKeys() {
  // 目前被选中的菜单节点
  const checkedKeys = proxy.$refs.AttrRef.getCheckedKeys()
  // 半选中的菜单节点
  // const halfCheckedKeys = proxy.$refs.AttrRef.getHalfCheckedKeys()
  // checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys)
  return checkedKeys
}
// 添加&修改 表单提交
function submitForm() {
  proxy.$refs["formRef"].validate((valid) => {
    if (valid) {
      form.value.attrIds = getAttrAllCheckedKeys()
      form.value.priceIds = getPriceAllCheckedKeys()
      form.value.layRoomSpecNav = layRoomSpecList.value
      if (form.value.id != undefined && opertype.value === 2) {
        updateLayRoom(form.value).then((res) => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addLayRoom(form.value).then((res) => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

// 删除按钮操作
function handleDelete(row) {
  const Ids = row.id || ids.value

  proxy
    .$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？', "警告", {
      confirmButtonText: proxy.$t('common.ok'),
      cancelButtonText: proxy.$t('common.cancel'),
      type: "warning",
    })
    .then(function () {
      return delLayRoom(Ids)
    })
    .then(() => {
      getList()
      proxy.$modal.msgSuccess("删除成功")
    })
}



// 导出按钮操作
function handleExport() {
  proxy
    .$confirm("是否确认导出房型表数据项?", "警告", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
    .then(async () => {
      await proxy.downFile('/business/LayRoom/export', { ...queryParams })
    })
}

/*********************房型规格表子表信息*************************/
const layRoomSpecList = ref([])
const checkedLayRoomSpec = ref([])
const fullScreen = ref(false)
const drawer = ref(false)

/** 房型规格表序号 */
function rowLayRoomSpecIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}

/** 房型规格表添加按钮操作 */
function handleAddLayRoomSpec() {
  let obj = {};
  //下面的代码自己设置默认值
  //obj.specName = null;
  //obj.specTitle = null;
  //obj.linePrice = null;
  //obj.dailyPrice = null;
  //obj.weekPrice = null;
  //obj.holidayPrice = null;
  //obj.remark = null;
  obj.status = '1';
  //obj.statusName = null;
  layRoomSpecList.value.push(obj);
}

/** 复选框选中数据 */
function handleLayRoomSpecSelectionChange(selection) {
  checkedLayRoomSpec.value = selection.map(item => item.index)
}

/** 房型规格表删除按钮操作 */
function handleDeleteLayRoomSpec() {
  if (checkedLayRoomSpec.value.length == 0) {
    proxy.$modal.msgError('请先选择要删除的房型规格表数据')
  } else {
    const LayRoomSpecs = layRoomSpecList.value;
    const checkedLayRoomSpecs = checkedLayRoomSpec.value;
    layRoomSpecList.value = LayRoomSpecs.filter(function (item) {
      return checkedLayRoomSpecs.indexOf(item.index) == -1
    });
  }
}

/** 房型规格表详情 */
function rowClick(row) {
  const id = row.id || ids.value
  getLayRoom(id).then((res) => {
    const { code, data } = res
    if (code == 200) {
      drawer.value = true
      layRoomSpecList.value = data.layRoomSpecNav
    }
  })
}
handleQuery()
</script>
<style>
/* 控制树形节点横向显示 */
.el-tree-node.is-expanded>.el-tree-node__children {
  display: flex !important;
  flex-wrap: wrap !important;
  /* flex横向布局换行显示 */
}

/* 去除点击收缩图标时：横向显示的数据会先晃动成纵向显示的再收缩的现象*/
.collapse-transition {
  transition: none !important;
}

.el-tree-node__content>.el-tree-node__expand-icon {
  box-sizing: border-box !important;
  display: none !important;
}
</style>
